<?php
header("Content-type:text/html; charset=utf-8");
include ("../conn.php");
$id = "";
if(isset($_GET['id'])) {
	$id= $_GET['id'];
}
$act = "";
if(isset($_GET['act'])) {
	$act= $_GET['act'];
}
//添加操作
if(isset($_POST['submit']) && ($act==""||$act=="create")){
	$username = trim(mysql_real_escape_string($_POST['username']));
	$pwd = trim(mysql_real_escape_string($_POST['pwd']));
	if(empty($username)){
		echo "用户名不可为空！<a href='admin_user.php'>返回</a>";
		exit;
	}
	if(empty($pwd)){
		echo "密码不可为空！<a href='admin_user.php'>返回</a>";
		exit;
	}
	$sql = "insert into admin(username,pwd,status) values ('".$username."','".$pwd."',1) ";
	//echo $sql;
	mysql_query($sql);
	echo "添加成功!<a href=admin_user.php>返回</a>";exit;
}
//修改操作
if(isset($_POST['submit']) && $act=="update"){
	$username = trim(mysql_real_escape_string($_POST['username']));
	$pwd = trim(mysql_real_escape_string($_POST['pwd']));
	if(empty($username)){
		echo "用户名不可为空！<a href='admin_user.php'>返回</a>";
		exit;
	}
	if(empty($pwd)){
		echo "密码不可为空！<a href='admin_user.php'>返回</a>";
		exit;
	}
	$sql = "update ".$databasepre."admin set username='".$username."',pwd='".$pwd."' where id=".$id;
	//echo $sql;
	mysql_query($sql);
	echo "修改成功!<a href=admin_user.php>返回</a>";exit;
}
//删除操作
if(isset($_GET['id'])&&$_GET['act']=="del")
{
	if(empty($id)){
		echo "请选择要删除的记录！<a href='admin_user.php'>返回</a>";
		exit;
	}

	$selectSQL="select count(*) as num from ".$databasepre."admin where status = 1";
	$query=mysql_query($selectSQL);

	$row=mysql_fetch_array($query);
	if($row['num']<2){
		echo "对不起，最后一个用户不可以删除！<a href='admin_user.php'>返回</a>";
		exit;
	}



	$delsql="delete from ".$databasepre."admin where id='".$id."'";
	mysql_query($delsql);
	echo "删除成功!<a href=admin_user.php>返回</a>";exit;
}
?>
<html><head>
<meta http-equiv=Content-Type content=text/html;charset=utf-8>
<link href="images/skin.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #EEF2FB;
}
-->
</style>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td valign="top" background="images/content-bg.gif">
		<table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
		  <tr><td height="31"><div class="titlebt">系统管理</div></td></tr>
		</table>
	</td>
    <td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9">
	<!-- 网页内容部分开始 -->


	<table width="100%" height="138" border="0" cellpadding="0" cellspacing="0">
      <tr><td height="13" valign="top">&nbsp;</td></tr>
	  <tr><td class="left_txt">当前位置：管理员用户管理</td></tr>
	  <!-- 一根线 -->
	  <tr><td height="20"><table width="100%" height="1" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC"><tr><td></td></tr></table></td></tr>
	  <!-- 说明信息 -->
	  <tr><td><table width="100%" height="55" border="0" cellpadding="0" cellspacing="0"><tr>
				<td width="10%" height="55" valign="middle"><img src="images/title.gif" width="54" height="55"></td>
				<td width="90%" valign="top"><span class="left_txt2">在这里，您可以根据您的网站需求，修改设置本网站的管理员。</span></td>
				</tr></table>
		</td>
	  </tr>
	  <tr><td>&nbsp;</td></tr>
	  <tr><td><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="nowtable">
				  <tr><td class="left_bt2">&nbsp;&nbsp;&nbsp;&nbsp;管理员用户管理【<a href=?act=create> 新 增 </a>】</td></tr>
				</table>
		</td>
      </tr>
	  <tr><td><table width="700" border="0" cellspacing="0" cellpadding="0">
				<form method=POST action="">

					<tr bgcolor="#f2f2f2">
						<th width="100" class="left_txt" align=left></th>
						<th width="200" height="30" class="left_txt2" align=left>用户名</th>
						<th width="100" class="left_txt2" align=left>密码</th>
						<th width="100" class="left_txt2" align=left>操作</th>
					</tr>

					<?php if($act=="" || $act=="create") { ?>
					<tr>
					<td height="30"></td>
					<td align=left><input type="text" name="username" value="" size="20" maxlength="40"/></td>
					<td align=left><input type="text" name="pwd" value="" size="30" maxlength="40"/></td>
					<td align=left><input type="submit" name="submit" value=" 添 加 " /></td>
					</tr>
					<?php
					}else if($act=="update"){
					$sql="select * from ".$databasepre."admin where id=".$id;
					$query=mysql_query($sql);
					$row=mysql_fetch_array($query);
					echo '<tr>';
					echo '<td height="30"></td>';
					echo '<td align=left><input type="text" name="username" value="'.$row['username'].'" size="20" maxlength="30"/></td>';
					echo '<td align=left><input type="text" name="pwd" value="'.$row['pwd'].'" size="20" maxlength="30"/></td>';
					echo '<td align=left><input type="submit" name="submit" value="修改" /></td>';
					echo '</tr>';

					}
					$tdstyle="";
					$tdi = 0;
					$sql="select * from ".$databasepre."admin where status=1 order by id asc";
					$query=mysql_query($sql);
					while($corprow=mysql_fetch_array($query))
					{
					$tdi = $tdi + 1;
					if($tdi%2 == 1) { $tdstyle = "f2f2f2"; }else{ $tdstyle = ""; }

					echo '<tr bgcolor='.$tdstyle.'>';
					echo '<td height="30"></td>';
					echo '<td align=left>'.$corprow['username'].'</td>';
					echo '<td align=left>'.$corprow['pwd'].'</td>';
					echo '<td align=left><a href=?act=update&id='.$corprow['id'].'>修改</a> <a href=?act=del&id='.$corprow['id'].'>删除</a></td>';
					echo '</tr>';
					}
					?>



				</form>
			  </table>
			</td>
		</tr>



	 </table>






	<!-- 网页内容部分结束 -->
	</td>
    <td background="images/mail_rightbg.gif">&nbsp;</td>
  </tr>
  <tr>
    <td valign="bottom" background="images/mail_leftbg.gif"><img src="images/buttom_left2.gif" width="17" height="17" /></td>
    <td background="images/buttom_bgs.gif"><img src="images/buttom_bgs.gif" width="17" height="17"></td>
    <td valign="bottom" background="images/mail_rightbg.gif"><img src="images/buttom_right2.gif" width="16" height="17" /></td>
  </tr>
</table>
</body>
</html>
